<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>文章列表--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:100%;" id="dataFrm">
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input telephone" name="telephone" lay-verify="required" placeholder="请输入手机号">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input password" name="password" lay-verify="required" placeholder="请输入密码">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">姓名:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input realname" name="realname" lay-verify="required" placeholder="请输入姓名">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">生日:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input birthday" name="birthday" lay-verify="required" placeholder="请输入生日">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <input type="hidden" id="himg" name="headimg">
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" src="resources/images/nopic.jpg" width="200px" height="200px">
                <p id="demoText"></p>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block available">
            <input type="radio" name="available" value="1" title="启用" checked>
            <input type="radio" name="available" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">所属部门:</label>
        <div class="layui-input-block">
            <select id="userDept" name="dept.id" class="userGrade" lay-filter="userDept">
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addUser">立即添加</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl','upload'],function() {
        var form = layui.form
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table,
            upload=layui.upload;

            //生日框的时间插件绑定
            laydate.render({
                elem:".birthday"
            });
            //上传图片
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/uploadImage2.do/' //上传接口,
            ,field:"headImage" //指定文件域名
            ,done: function(res){
                layer.msg(res.msg);
                $("#himg").val(res.data);
            }
            ,error: function(){
                //请求异常回调
            }
            , before:function (res) {
                //上传之前预读本地文件示例
                res.preview(function (index,file,result) {
                    $("#demo1").attr("src",result);
                })
            }
        });
        //请求获取数据
        //动态绑定下拉菜单的数据
        form.render('select');
        form.on("submit(addUser)",function (data) {
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            //实际使用时的提交数据
            var params=$("#dataFrm").serialize();
            console.log(params);
            $.post("users.do",params,function (res) {
                console.log(res.code);
                if(res.code==2001){
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    var index1=parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index1);
                    parent.location.reload();
                }else if(res.code=-1004){
                    layer.msg(res.msg);
                }else if(res.code=-2001){
                    layer.msg(res.msg);
                }
            },"json");
            return false;
        });
    });
</script>
</body>
</html>